// pages/tabBar/specialty/specialty.js
const http = require("../../../utils/httpUtils.js");
const app = getApp();
Page({
    data: {
        height: app.globalData.height,
        navHei: 0,
        tabs: ["热销爆款", "好友拼团"],
        currentTab: 0,
        cate: []
    },
    onLoad(options) {
        this.navWrapHeight() // 获取导航栏的高度
        this.index()
    },
    index() {
        http._get('/api/Goods/goods_index', {
            'c_client': 'weixinSmall',
            'v': '1.1.0'
        }, res => {
            if (res.data.code == 1) {
                let data = res.data.data;
                this.setData({
                    cate: data.goods_list
                })
                wx.stopPullDownRefresh()
            }
        })
        http._get('/api/Ad/get_list', {
            'c_client': 'weixinSmall',
            'ad_page': '4',
            'v': '1.1.0'
        }, res => {
            if (res.data.code == 1) {
                let data = res.data.data;
                this.setData({
                    carousel: data
                })
            }
        })
        http._get('/api/GoodsCategory/getCateList', {
            'c_client': 'weixinSmall',
            'type': 'goods_index',
            'v': '1.1.0'
        }, res => {
            if (res.data.code == 1) {
                let data = res.data.data;
                this.setData({
                    activity: data.activity,
                    classification: data.cate
                })
            }
        })

    },
    //点击切换
    clickTab: function(e) {
        let that = this;
        if (this.data.currentTab === e.target.dataset.current) {
            return false;
        } else {
            that.setData({
                currentTab: e.target.dataset.current
            })
        }
    },
    // 获取导航栏的高度
    navWrapHeight() {
        let query = wx.createSelectorQuery()
        query.select('.nav-wrap').boundingClientRect((res) => {
            this.data.navHei = res.height
        }).exec();
    },
    detail(e) { //进入商品详情
        let id = e.currentTarget.dataset.id;
        wx.navigateTo({
            url: `/pages/public/goods_detail/index?id=${id}`,
        })
    },
    Category() { //大分类列表
        wx.navigateTo({
            url: `/pages/tabBar/mall/category/index`,
        })
    },
    plantingDetail(e) { // 轮播图跳转文章详情
        let dataset = e.currentTarget.dataset;
        if (dataset.type == 1) {
            wx.navigateTo({
                url: `/pages/public/goods_detail/index?id=${dataset.id}`
            })
        }
    },
    cart() { // 购物车
        wx.navigateTo({
            url: '/pages/shop-cart/index',
        })
    },
    search() { // 搜索链接
        wx.navigateTo({
            url: `/pages/tabBar/index/search/se`,
        })
    },
    getList(e) { //获取分类列表
        // console.log(e)
        let gc_id = e.currentTarget.dataset.gc_id;
        let data = {
            gc_id: gc_id,
            page: 1
        }
        if (e.currentTarget.id == "") {
            wx.navigateTo({
                url: `/pages/public/activity_list/index?queryData=${JSON.stringify(data)}`,
            })
        } else {
            wx.navigateTo({
                url: `/pages/tabBar/mall/category/index?queryData=${JSON.stringify(data)}`,
            })
        }

    },
    onPullDownRefresh() {
        this.index();
    },
    onShareAppMessage() {
        return {
            title: `打造地方最具代表性、独特性的"家乡特色名片"`
        }
    }
})